﻿#pragma once
#include "oatpp/web/server/HttpRequestHandler.hpp"
#include "oatpp/web/url/mapping/Pattern.hpp"
#include "../log/SysLog.h"

class HelloHandler
	: public oatpp::web::server::HttpRequestHandler
{
public:
	std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) override {
		// path参数解析
		auto path_vars = request->getPathVariables();
		auto pvars = path_vars.getVariables();
		for (auto it = pvars.begin(); it != pvars.end(); ++it)
		{
			auto key = it->first;
			auto value = it->second;
			LOG_INFO("path variable: {}-{}", key.getData(), value.getData());
		}

		// 查询参数解析
		auto query_vars = request->getQueryParameters();
		auto qvars = query_vars.getAll();
		for (auto it = qvars.begin(); it != qvars.end(); ++it)
		{
			auto key = it->first;
			auto value = it->second;
			LOG_INFO("query variable: {}-{}", key.getData(), value.getData());
		}

		// body参数解析
		if (false)
		{
			auto json = request->readBodyToString();
			LOG_INFO("body: {}", json.getValue(""));
		}
		return ResponseFactory::createResponse(Status::CODE_200, "Hello, World!");
	}
};